package com.mjf.tankgame.v5;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

public class TankGame05 extends JFrame {

    // 定义MyPanel
    MyPanel mp = null;

    public static void main(String[] args) {

        TankGame05 tankGame05 = new TankGame05();
    }

    public TankGame05() {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入选择 【1: 新游戏 2: 继续上局】");
        String key = scan.next();
        mp = new MyPanel(key);

        // 将 mp 放入到Thread ,并启动不停重新绘制
        Thread thread = new Thread(mp);
        thread.start();

        this.add(mp);   // 把面板(就是游戏的绘图区域)
        this.setSize(1300, 950);
        this.addKeyListener(mp);    // 让 JFrame 监听mp的键盘事件
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        // 在 JFrame 中增加相应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.saveRecord();
                System.exit(0);
            }
        });
    }
}